// xc_lshop/distr/manage/orderlist/areaorder.js
var actbill = require('../../model/distribution_team.js')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    curid:"",
    nav:[],

  },
  onclickitem(e){
    console.log("dddd")
    console.log(e)
    var item=e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/xc_lshop/distr/manage/orderlist/arealistorder?curid='+this.data.curid+"&areaname="+item.areaname,
    })

  },
  onlicknav(e){
     var id=e.currentTarget.dataset.id
     this.setData({
       curid:id
     })
     this.getpagelist(1)
  },
  getbasic(){
    var that = this
    actbill.accumulated().then(function (res) {
        console.log("res")
        console.log(res)
        if(res['status']==1){
          that.setData({
            accumulated:res['obj']
          })
        }
        

    })
  },
  setconfig(config){
    console.log("dddddddddd")
    console.log(config.distribution)
    this.setData({
      distributionconfig:config.distribution
    })

  },
  xcloaddata: function (options, config) {
  
    this.setconfig(config)
    this.gettimlist(1)
  },
  getpagelist(rest, strwhere) {
    var that = this
    if (rest == 1) {
      that.setData({
        modellist: []
      });
      if (!strwhere) {
        strwhere = {}
      }
      strwhere["time"] = this.data.curid
    }
    this.setData({
      isload: true
    })
    actbill.areaorderoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      updatemdoel["isload"] = false
      that.setData(updatemdoel);
    })
    return;
  },
  loadinglist(){
    var page= this.data.page + 1;
    var navdata= this.data.navdata;
    console.log(navdata)
    this.gettimlist(page,5,navdata)
  },
  gettimlist(page,limit=5,data=null){
    var date=new Date();
    var nowmonth="";
    var nowyear="";
    if(page==1){
      nowmonth=date.getMonth()+1;
      nowyear=date.getFullYear();
    }else{
      nowmonth=data['month'];
      nowyear=data['year'];
    }
    var list=[]
    for(var i=0;i<limit;i++){
      
      var item={}
      item['name']=nowyear+"年"+nowmonth+"月";
      item['id']=nowyear+"-"+ (nowmonth<10?'0'+nowmonth:nowmonth)
      list.push(item)

      nowmonth=nowmonth - 1;
      if(nowmonth==0){
        nowmonth=12;
        nowyear= nowyear - 1
      }
    }
    var updata={ }
    updata["page"]=page;
    updata["nav"]=this.data.nav.concat(list);
    updata["navdata"]={month:nowmonth,year:nowyear};

    if(page==1){
      updata["curid"]=list[0]['id'];
    }

    this.setData(updata)

    if(page==1){
      this.getbasic()
      this.getpagelist(1)
    }
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // decodeURIComponent(options.areaname);
    // options.areaname=encodeURI(options.areaname)
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getpagelist(-1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})